/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: IteratorImpl.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/17 下午2:30
 * LastModified: 2020/03/17 14:30:17
 */

package com.qolome.knowledge.design.pattern.iterator.demo;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

 /**
 * @author Qolome
 * @version V1.0
 * @Description 待代 器实现
 * @date 2020年 03月17日 14:30:15
 */
@Slf4j
public class IteratorImpl<E> implements Iterator{

    private List<E> list;
    private int cursor;
    private E element;

    public IteratorImpl (List<E> list){
        this.list = list;
    }


   @Override
    public E next() {
       log.info("当前位置:{}",cursor);
       element = list.get(cursor);
       cursor++;
        return element;
    }

    @Override
    public boolean hasNext() {
        return  cursor< list.size();
    }
}
